<?php if(isset($models)) : ?>

<div class="clearfix offset4">
  <div id="navigation">
    <a class="prev" href="#"></a>
    <a class="next" href="#"></a>
    <a class="large zoom" rel="lightbox" href=""></a>
  </div>
</div>

<div class="span12 description">
  <?php print render($video); ?>
  <?php print render($description); ?>
</div>

<div class="span12 row">
  <ul class="thumbnails models">

    <?php
    $active = true;
    $pager_map = array_keys($models);

    foreach($models as $key => $model) {
      $fields = field_get_items('lonex_category_item', $model, 'field_model_images');
      $file = file_create_url($fields[0]['uri']);

      $current_index = array_search($key ,$pager_map);

      $prev = isset($pager_map[$current_index-1]) ? $pager_map[$current_index-1] : 0;
      $next = isset($pager_map[$current_index+1]) ? $pager_map[$current_index+1] : 0;

      print '<li class="span2">' .
        l('<img src="'.$file.'"/><div>' . check_plain($model->title) . '</div>', 'catalog/' . $model->cid . '/' . $model->ciid,
          array(
            'attributes' => array(
              'class' => array('use-ajax','thumbnail',$active ? 'active' : '', 'model-' . $model->ciid),
              'prev' => $prev,
              'next' => $next,
            ),
            'html' => true)) . '</li>';

      $active = false;
    }

    ?>

  </ul>
</div>
<?php endif; ?>